﻿namespace FSAG.UserImporter
{
    /// <summary>
    /// List of status types for the status messages
    /// </summary>
    public enum StatusType
    {
        /// <summary>
        /// Information used for normal information messages
        /// </summary>
        Information,

        /// <summary>
        /// Exception used in case of an error 
        /// </summary>
        Exception
    }

    /// <summary>
    /// Contains the status message and status type
    /// </summary>
    public class ExcelStatus
    {
        /// <summary>
        /// Determines whether the specified object is equal to the current object.
        /// </summary>
        /// <param name="other">The object to compare with the current object</param>
        /// <returns>True if the specified object is equal to the current object; otherwise, false.</returns>
        protected bool Equals(ExcelStatus other)
        {
            return StatusType == other.StatusType && string.Equals(StatusMessage, other.StatusMessage);
        }

        /// <summary>
        /// Serves as a hash function for a particular type.
        /// </summary>
        /// <returns>A hash code for the current Object.</returns>
        public override int GetHashCode()
        {
            unchecked
            {
                return ((int) StatusType*397) ^ (StatusMessage != null ? StatusMessage.GetHashCode() : 0);
            }
        }

        /// <summary>
        /// Contains the status type of the current status
        /// </summary>
        public StatusType StatusType { get; set; }

        /// <summary>
        /// Contains the status message of the current status
        /// </summary>
        public string StatusMessage { get; set; }

        /// <summary>
        /// Returns a string representation of the status type
        /// </summary>
        public string StatusTypeAsString
        {
            get
            {
                switch (StatusType)
                {
                    case StatusType.Exception:
                        return "Fehler";

                    default:
                        return "Information";
                }
            }
        }

        /// <summary>
        /// Determines whether the specified object is equal to the current object.
        /// </summary>
        /// <param name="x">The object to compare with the current object</param>
        /// <returns>True if the specified object is equal to the current object; otherwise, false.</returns>
        public override bool Equals(object x)
        {
            if (ReferenceEquals(null, x)) return false;
            if (ReferenceEquals(this, x)) return true;
            if (x.GetType() != GetType()) return false;
            return Equals((ExcelStatus) x);
        }
    }
}